<?php
session_start();
$user = $_SESSION['user'];



?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="../ico/logo.ico" type="image/x-icon" />
    <title>协同办公-公告</title>
    <link rel="stylesheet" href="../../static/css/bootstrap.css">
    <link rel="stylesheet" href="../../static/js/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/main.css">
    <style>
        #title-form{
            width: 90px;
        }
    </style>
</head>
<body>
<div id="logo"><div id="logo-img"><img src="../../static/imaegs/logo/logo2.png"></div>
<div id="logo-right">
    <h5 ><i class="layui-icon" style="font-size: 18px; color: orange">&#xe645;</i>&nbsp;最新公告：<span id="notice">暂无公告</span></h5>

</div>
</div>
<div id="tiao">
    <div id="left"><a href="../index.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe68e;</i>&nbsp;首页</a>
    <a href="../task.php"> <i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe6b2;</i>&nbsp;任务</a>
        <a style="color:blue;border-bottom: 2px blue solid"> <i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe637;</i>&nbsp;公告栏</a>
        <a href="../file.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe621;</i>&nbsp;文件管理</a>
        <a href="../add_user.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe613;</i>&nbsp;用户管理</a></div>
    <div id="right"><a style="color:grey">您好！&nbsp;</a><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe66f;</i><input id="user" name="user" readonly="readonly" value="<?php echo $user ?>"><a href="../login.html">退出</a></div>
</div>
<hr class="layui-bg-gray">
<div id="from_block">


        <legend><i class="iconfont" style="color: #0b3b8c">&#xe6b2;写公告：</i></legend>
    <div class="layui-form-item">
        <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b8;</i>标题：</label>
        <div class="layui-input-inline login-inline">
            <input type="text" name="title" id="title" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
        <input type="text"  name="user" id="user" style="display: none"  value="<?php echo $user; ?>">
            <div class="layui-input-block">
                <textarea class="layui-textarea" maxlength="200" id="content" name="content" placeholder="请输入内容,内容字数不超过300字"></textarea>
                <br>
                 <button class="layui-btn layui-btn-warm" lay-submit lay-filter="login" style="margin-left: 300px" onclick="release()" type="button">确认发布</button>
                <button class="layui-btn" onclick="sendOut()">邮件群发</button>
<hr>温馨提示：邮件发送失败，请正确配置自己的邮箱哦
            </div>
    <legend><i class="iconfont" style="color: #0b3b8c">&#xe60e;公告列表：</i></legend>
    <hr class="layui-bg-blue">
        <div class="layui-row layui-col-space15" >
            <div class="layui-col-md12" id="uul">
            </div>
        </div>






</div>
<hr>

<img id="hua1" src="../../static/imaegs/122.png">
<div id="footer">
    <hr>
    <a id="fot-word">
        版权信息：xianghai保留所有权利，请尊重他人的劳动成果   ||    备案号：蜀ICP备18021117号
        ||           地址：四川省成都市高新区天一街83号软件大楼
    </a>
</div>
<ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-slot="3820120620" data-ad-client="ca-pub-6111334333458862"></ins>

<script src="../../static/js/jquery.min.js"></script>
<script src="../../static/js/layui/layui.all.js"></script>
<script>

    $user=$('#user').val();
    if($user===""){
        layer.msg("您还没有登陆哦！");
        window.location.href="login.html";

    }




    function release() {
        var user_name = document.getElementById("user"),
           content=document.getElementById("content"),
        title=document.getElementById("title");
        $user = user_name.value;
        if(title.value===""){
            layer.msg("你的标题还没有填写哦");
            return false;

        }
        else if(content.value==="") {
            layer.msg ('公告内容还没有填写');
            return false;
        }

        else {

            $content=content.value;
            $title=title.value;
            $.ajax({
                type: 'post',
                cache: 'false',
                url: '../../php/admin/add_notice.php',
                data: {
                    "user": $user,
                    "content": $content,
                    "title":$title,
                },
                dataType: 'Json',
                success: function (dat) {
                    layer.msg(dat.message);


                },
                error: function (dat) {
                    layer.msg("发布失败，请检查网络是否正常");
                }


            })


        }







    }

    $.ajax({
        type: 'post',
        cache: false,
        url: '../../php/admin/select_notice.php',
        data: {
            "user":$user,
        },
        dataType: 'json',
        success: function (data) {
            $coun = data.count;
            $dat = data.data;
            // var dataCount=document.getElementById("dataSum");
            // dataCount.innerHTML=$coun;
            $notice=$dat[0].content;
            var not=document.getElementById("notice");
            not.innerHTML=$notice;
            for ($i = 0; $i < $coun; $i++) {
                $id = $dat[$i].id;
                $user = $dat[$i].no_admin;
                $title=$dat[$i].title;
                $content=$dat[$i].content;
                $addtime=$dat[$i].no_addtime;
                var date=new Date(parseInt($addtime)*1000);
                Y=date.getFullYear()+'年';
                M=(date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1)+'月';
                D=date.getDate()+'日';
                h=date.getHours()+':';
                m=date.getMinutes()+':';
                s=date.getSeconds();
                $date=Y+M+D+h+m+s;
                var li_id = $id;
                $li = $(" <div id="+$id+" class=\"layui-card\" id=\"card\">\n" +
                    "<div class=\"layui-card-header\">"+"主题："+$title+"<button style=\"float: right;margin-top: 3px\" class=\"layui-btn layui-btn-primary layui-btn-sm\" onclick='del("+$id+")'><i class=\"layui-icon\"></i></button>"+"</div>\n" +
                    "                    <div class=\"layui-card-body\">\n" +$content+"<br>" +
                    "                       <span id=\"time\">"+ "发布时间："+$date+"&nbsp;|&nbsp;"+"发布人："+$user+"</span>" +
                    "                          <br>\n" +
                    "                    </div>\n" +
                    "                </div>");
                $("#uul").append($li);

            }
        },
        error: function (data) {
            layer.msg("暂无公告");
        }
    });
     function del($id) {
         layer.confirm('真的删除行么', function(index) {
             $.ajax({
                 type:'post',
                 cache:'cache',
                 url:'../../php/admin/del_notice.php',
                 data:{
                     "id":$id,
                 },
                 dataType:'json',
                 success:function (dat) {
                     layer.msg(dat.message);
                     var li=document.getElementById($id);
                     li.remove();
                 },
                 error:function (dat) {
                     layer.msg("删除失败")
                 },

             });
         });





}
function sendOut() {


    var not_user= document.getElementById("user"),
        not_content=document.getElementById("content"),
        not_title=document.getElementById("title");
    $user = not_user.value;
    if(not_title.value===""){
        layer.msg("你的标题还没有填写哦");
        return false;

    }
    else if(not_content.value==="") {
        layer.msg ('公告内容还没有填写');
        return false;
    }

    else {
        $content = not_content.value;
        $title = not_title.value;
        $.ajax({
            type: 'post',
            cache: 'false',
            url: '../../php/phpmail/sendnotice.php',
            data: {
                "user": $user,
                "content": $content,
                "title": $title,
            },
            dataType: 'Json',
            success: function (dat) {
                layer.msg(dat.message);

            },
            error: function (dat) {
                layer.msg("群发成功！");
            }


        })
    }
}
</script>

</body>
</html>